package com.example.thead_010;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;

public class MainActivity extends Activity {
	
	Button button1 = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button1 = (Button) findViewById(R.id.button1);
        Button button2 = (Button) findViewById(R.id.button2);
        
        Animation animation = new TranslateAnimation(0, 150, 0, 0);
        animation.setRepeatCount(30);
        animation.setDuration(6000);
        button1.setAnimation(animation);
        
       /* button2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View view) {
				Toast.makeText(MainActivity.this, "click", Toast.LENGTH_SHORT).show();
				new Thread(new Runnable() {
					
					@Override
					public void run() {
						try {
							Thread.sleep(6000);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}).start();
				view.post(new Runnable() {
					
					@Override
					public void run() {
						button1.setText("I change it");
					}
				});
			}
		});*/
        button2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				new myTask().execute();
			}
		});
    }
    
    private class myTask extends AsyncTask<String, Void, String>{
		@Override
		protected String doInBackground(String... arg0) {
			return "I change it too";
		}
		@Override
		protected void onPostExecute(String message){
			button1.setText(message);
		}
		
    	
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}
